package com.itheima79.googleplay.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.reflect.TypeToken;
import com.itheima79.googleplay.adapter.BasicAdapter;
import com.itheima79.googleplay.adapter.SubjectAdapter;
import com.itheima79.googleplay.bean.Subject;
import com.itheima79.googleplay.http.Api;
import com.itheima79.googleplay.http.HttpUtil;
import com.itheima79.googleplay.util.CommonUtil;
import com.itheima79.googleplay.util.JsonUtil;

public class SubjectFragment extends BaseListFragment<Subject> {
	
	@Override
	protected BasicAdapter<Subject> getAdapter() {
		return new SubjectAdapter(list);
	}

	@Override
	protected Object requestData() {
		String result = HttpUtil.get(Api.Subject+list.size());
		ArrayList<Subject> subjects = (ArrayList<Subject>) JsonUtil.parseJsonToList(result,new TypeToken<List<Subject>>(){}.getType());
		
		if(subjects!=null){
			list.addAll(subjects);//更新数据
			
			CommonUtil.runOnUIThread(new Runnable() {
				@Override
				public void run() {
					adapter.notifyDataSetChanged();
					refreshListView.onRefreshComplete();
				}
			});
		}
		
		return subjects;
	}

	
}
